package com.wqr.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wqr.pojo.LogInfo;
import com.wqr.service.LogInfoService;

@Controller
public class LogInfoController {
	@Autowired
    public LogInfoService logInfoService;
	
	@RequestMapping("/manageLogInfo")
	public String logInfo(Model model) throws Exception {
		List<LogInfo> list = logInfoService.list();
		model.addAttribute("itemList", list);
	    return "manageLogInfos"; 
	}
	
	@RequestMapping("/searchLogInfo")
	public String searchLogInfo(String txtSearchLoginDateTimeBegin,
			String txtSearchLoginDateTimeEnd,String txtSearchLoginName,
			String txtSearchEescription,LogInfo logInfo,Model model) throws Exception {
		DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if(txtSearchLoginDateTimeBegin.length() != 0){
			logInfo.setLoginTimeBegin(fmt.parse(txtSearchLoginDateTimeBegin));
		}else {
			logInfo.setLoginTimeBegin(null);
		}
		if(txtSearchLoginDateTimeEnd.length() != 0){
			logInfo.setLoginTimeEnd(fmt.parse(txtSearchLoginDateTimeEnd));
		}else {
			logInfo.setLoginTimeEnd(null);
		}
		if(txtSearchEescription.length() != 0) {
			logInfo.setDescription(txtSearchEescription);
		}else {
			logInfo.setDescription(null);
		}
		if(txtSearchLoginName.length() != 0) {
			logInfo.setLoginName(txtSearchLoginName);
		}else {
			logInfo.setLoginName(null);
		}
		List<LogInfo> itemList = logInfoService.selectLogInfo(logInfo);
		model.addAttribute("itemList",itemList); 
		model.addAttribute("search",itemList); 
		return "manageLogInfos";
	}
}
